from download import download_github_most_stars
from filter import filter
from report import report_csv
import os
import time
import re

if __name__ == "__main__":
  try:
    date_str = time.strftime("%Y_%m_%d", time.localtime())

    download_github_most_stars(f'data/most_stars/{date_str}.json')

    time.sleep(1)
    
    # for src_file in os.listdir('data/most_stars'):
    #   if re.match(r"^\d{4}_\d{2}_\d{2}\.json$", src_file):
    #     filter(f'data/most_stars/{src_file}', f'data/resources/{src_file}', f'data/populars/{src_file}')
    filter(f'data/most_stars/{date_str}.json', f'data/resources/{date_str}.json', f'data/populars/{date_str}.json')
    
    time.sleep(1)

    files = os.listdir('data/populars')
    report_csv([f'data/populars/{file}' for file in files if re.match(r"^\d{4}_\d{2}_\d{2}\.json$", file)])

  except Exception as e:
    print(e)